package com.example.shoppingmall.service;


import com.example.shoppingmall.dao.UserMapper;
import com.example.shoppingmall.pojo.User;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class UserService implements UserDetailsService{
    @Autowired
    UserMapper userMapper;

    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        User user = userMapper.loadUserByUsername(username);
        if (user == null) {
            throw new UsernameNotFoundException("账户不存在!");
        }
        return user;
    }

    public List<User> getAll(@Param("userPhone")String userPhone,
                             @Param("username")String username,
                             @Param("inviterPhone")String inviterPhone, @Param("no")int no){
        return userMapper.getAll(userPhone,username,inviterPhone,no);
    }

    public int userCount(@Param("userPhone")String userPhone, @Param("username")String username, @Param("inviterPhone")String inviterPhone){
        return userMapper.userCount(userPhone,username,inviterPhone);
    }

    public int add(User user){
        return userMapper.add(user);
    }

    public User xiangqing(@Param("id")int id){
        return userMapper.xiangqing(id);
    }

    public int update(User user){
        return userMapper.update(user);
    }

    public int update1(User user){
        return userMapper.update1(user);
    }

    public int updateUserBalance(User user){
        return userMapper.updateUserBalance(user);
    }

    public int updateUserIntegral(User user){
        return userMapper.updateUserIntegral(user);
    }

    public int updateInviterPhone(User user){
        return userMapper.updateInviterPhone(user);
    }

    public int delete(@Param("id")int id){
        return userMapper.delete(id);
    }

    public User checkUserPhone(@Param("userPhone")String userPhone){
        return userMapper.checkUserPhone(userPhone);
    }

    public int chackUserAccount(@Param("userAccount")String userAccount){
        return userMapper.chackUserAccount(userAccount);
    }

    public User getuserimg(String userAccount){
        return userMapper.getuserimg(userAccount);
    }
}
